package com.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.entity.Permissions;
import com.service.UserRoleService;


@Controller
@RequestMapping("role")
public class UserRoleController {
	@Autowired
	UserRoleService roleService;
	@RequestMapping("list")
	public String roleList(Model model) {
		model.addAttribute("roleList", roleService.selectAll());
		return "developer/rolelist";
	}
	
	@RequestMapping("permis")
	public String rolePermis(Long id,Model model){
	
		model.addAttribute("id",id);
		model.addAttribute("permisList", roleService.selectPermissionsByRoleId(id));
		return "developer/rolePermislist";
	}
	
	@ResponseBody
	@RequestMapping("auth")
	public Boolean roleAuth(Long roleId,Long[] data,Model model){
	for (Long long1 : data) {
		System.out.println(long1);
	}
		return roleService.addRolePermission(roleId, data) > 0;
	}
	
	/**
	 * zTree 加载
	 * @param roleId
	 * @param model
	 * @return
	 */
	@ResponseBody
	@RequestMapping("permission")
	public List<Permissions> permission(Long roleId,Model model){
	
		return roleService.selectRolePermissions(roleId);
	}

}
